<!--
 * @Author: JiraiyaChen 979526234@qq.com
 * @Date: 2025-03-13 13:28:58
 * @LastEditors: JiraiyaChen 979526234@qq.com
 * @LastEditTime: 2025-03-31 15:33:49
 * @Description: 选择模板
-->

<template>
  <ClDialog v-bind="$attrs" :title="getTitle" width="1390px">
    <ClBar bar-height="650px">
      <el-tabs v-model="activeName" stretch>
        <el-tab-pane label="模板库" name="templateLibrary">
          <ModelTable ref="modelTable" />
        </el-tab-pane>
        <el-tab-pane label="项目模板" name="projectTemplate">
          <ProjectTable ref="projectTable" />
        </el-tab-pane>
      </el-tabs>
    </ClBar>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emit('atClose')">取消</el-button>
        <el-button type="primary" :loading="btnLoading" @click="onSure">确定</el-button>
      </span>
    </template>
  </ClDialog>
</template>

<script setup lang="ts">
import ModelTable from './components/ModelTable.vue'
import ProjectTable from './components/ProjectTable.vue'
import { bandTemplateOrProjectItem } from '@/api/project-scoring-standard-configuration'
const modelTable = ref()
const projectTable = ref()
const btnLoading = ref(false)
const onSure = async () => {
  try {
    btnLoading.value = true
    const res: any[] = []
    // 模板库
    if (activeName.value === 'templateLibrary') {
      const targetId = modelTable.value.currentId
      targetId &&
        (await bandTemplateOrProjectItem({
          targetId,
          type: 'template'
        }))
    }
    // 项目模板
    if (activeName.value === 'projectTemplate') {
      const targetId = projectTable.value.currentId
      targetId &&
        (await bandTemplateOrProjectItem({
          targetId,
          type: 'project'
        }))
    }

    emit('atClose', 'refresh-table')
    btnLoading.value = false
  } catch (error) {
    btnLoading.value = false
  }
}

const activeName = ref('templateLibrary')
const getTitle = computed(() => {
  return props.type
})

interface infoType {
  [props: string]: any
}
const props = defineProps<{ info: infoType; type: string }>()

const emit = defineEmits(['atClose', 'selection-arr'])
</script>

<style scoped lang="scss"></style>
